
// variables to hold the different views

// Holds all the different order states for easy access
var availableOrderStates = [];

// List of Customer objects
var savedCustomers = [];

// List of Order objects
var savedOrders = [];


$(document).ready(function() {
	
	$("#tabs").hide();
	$("#loading").show();
    
    // Tabbladen aanmaken
    $("#tabs").tabs({
        disabled: [0,1,2],
        select: function(event, ui) {
            switch($(ui.tab).attr("name")) {
                case "customers" : 
                    CustomerService.RenderCustomers();
                    break;
            
                case "orders" : 
                    OrderService.RenderOrders();
                    break;
            }
        }
    });
    
    // Settings inladen
    SettingsService.LoadSettings(function() {
		// Beschikbare order staten ophalen
		OrderStatesService.LoadOrderStates();
        
        // Adressen ophalen
        AddressService.LoadAddresses();
		
		// Klanten laden
		CustomerService.LoadCustomers();
		
		// Orders laden
		OrderService.LoadOrders();
		
		$("#tabs").show();
		$("#loading").hide();
	});
	
	
    
    
    // View Customer handler
    $(".ViewCustomer").live('click', function() {
        var customerID = $(this).attr("customerid");
        
        // De juist tab openen
        $("#tabs").tabs("select", "customers");
        
        // De juiste klant selecteren
        $("#customer_list").accordion("activate", "#customer_" + customerID);
    });
    
    
    // Save settings handler
    $("#btnSaveSettings").click(function() {
        // Settings opslaan
        SettingsService.SaveSettings();
        
        // Credentials checken
        PrestashopService.CheckCredentials();
    });
	
	
	// Clear cache button handler
	$("#btnClearCache").click(function() {
		SettingsService.ClearCache();
	});
	
	
	// Reset config button handler
	$("#btnResetConfig").click(function() {
		SettingsService.ResetSettings();
	});
    
});


